import wx from 'weixin-js-sdk'

export default {
  location (wechatConfig) {
    wechatConfig.jsApiList = ['getLocation']
    wx.config(wechatConfig)
    wx.ready(function () {
      wx.getLocation({
        type: 'wgs84',
        success: function (res) {
          debugger
        }
      })
    })
    wx.error(function (res) {
      console.log(res)
    })
  },
  share (wechatConfig, shareConfig) {
    shareConfig.jsApiList = ['onMenuShareTimeline', 'onMenuShareAppMessage']
    wx.config(shareConfig)
    wx.ready(function () {
      // 分享到朋友圈
      wx.onMenuShareTimeline({
        title: shareConfig.title,
        link: shareConfig.link,
        imgUrl: shareConfig.imgUrl,
        success: function () {
          console.log('分享成功。')
        }
      })
      // 分享到朋友
      wx.onMenuShareAppMessage({
        title: shareConfig.title,
        desc: shareConfig.desc,
        link: shareConfig.link,
        imgUrl: shareConfig.imgUrl,
        type: shareConfig.type,
        dataUrl: shareConfig.dataUrl,
        success: function () {
          console.log('分享成功。')
        }
      })
    })
    wx.error(function (res) {
      console.log(res)
    })
  }
}
